/* 
 * given an array of integers, find two numbers
 * such that they add up to a specific target number
 * 
 * numbers={2,7,11,15}, target=9
 */

#include "../../func.h"

vector<int> towSum(vector<int> &nums, int target)
{
    unordered_map<int , int> mapp;
    vector<int> result;
    for (int i = 0; i < nums.size(); ++i)
    {
        mapp[nums[i]] = i;
    }

    for (int i = 0; i < nums.size(); ++i)
    {
        const int gap = target - nums[i];
        if (mapp.find(gap) != mapp.end() && mapp[gap] > i)
        {
            result.push_back(i+1);
            result.push_back(mapp[gap] + 1);
            break;
        }
    }
    return result;
}